import { defHttp } from "/@/utils/http/axios";
import { Modal } from "ant-design-vue";

export enum Api {
  list      = "/cmsMemberController/dataGrid",
  treeGrid  = "/cmsMemberController/treeGrid",
  save      = "/cmsMemberController/save",
  delete    = "/cmsMemberController/delete",
  queryById = "/cmsMemberController/queryById",
  auditPc   = "/cmsMemberController/auditPc",
  approvalPc= "/cmsMemberController/approvalPc",
  select    = "/cmsMemberController/treeSelect",
  update    = "/cmsMemberController/update",
  memberUpdate    = "/cmsMemberController/memberUpdate",
  setCustomerInfo = "/weixinCustomerController/getCustomer",
  searchCustomer  = "/weixinCustomerController/search",
}

//TODO -----------订单列表 ---------------------------------------------
/**
 * 订单 - 列表
 * @param params
 */
export const list = (params) => defHttp.get({url: Api.list, params}, {joinParamsToUrl: true});

/**
 * 会员管理 - 列表
 * @param params
 */
export const treeGrid = async (params) => await defHttp.get({url: Api.treeGrid, params});

/**
 * 会员管理 - 通过ID获取数据
 * @param params
 */
export const queryById = (params) => defHttp.get({url: Api.queryById, params});

/**
 * 会员管理 - 保存或者更新
 * @param params
 */
export const save = (params) => {
  return defHttp.post({url: Api.save, params}, {isTransformResponse:false});
}

/**
 * 会员管理 - 审核
 * @param params
 */
 export const auditPc = (params) => defHttp.get({url: Api.auditPc, params});

/**
 * 会员审核
 * @param params
 */
export const approvalPc = (params) => {
  return defHttp.get({url: Api.approvalPc, params}, {isTransformResponse:false});
}

/**
 * 会员管理 - 保存或者更新
 * @param params
 */
export const update = (params) => {
  return defHttp.post({url: Api.update, params}, {isTransformResponse:false});
}

/**
 * 会员管理 - 保存或者更新
 * @param params
 */
export const memberUpdate = (params) => {
  return defHttp.post({url: Api.memberUpdate, params}, {isTransformResponse:false});
}

/**
 * 会员管理 - 通过ID删除数据
 * @param params
 */
export const del = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 会员姓名+电话
 */
export const setCustomerInfo = (params) => {
  return defHttp.get({url: Api.setCustomerInfo, params}, {isTransformResponse:false});
}

/**
 * 查询单位名称
 */
export const searchCustomer = (params) => {
  return defHttp.get({url: Api.searchCustomer, params}, {isTransformResponse:false});
}